package com.ssy.lingxi.enhance.constant;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 生产通知单外部状态 - enum
 * @author fhj
 * @date 2020/10/16
 * @version 2.0.0
 */
public enum PNOOuterStatusEnum {

    TO_BE_SUBMIT(1, "待提交"),
    TO_BE_CONFIRM(2, "待确认"),
    TO_BE_ADD_DELIVERY(3, "待新增加工发货单"),
    TO_BE_ADD_LOGISTICS(4, "待新增物流单"),
    TO_BE_DELIVERY(5, "待发货"),
    TO_BE_ADD_STORAGE(6, "待新增加工入库单"),
    TO_BE_RECEIVE(7, "待收货"),
    TO_BE_CONFIRM_RECEIPT(8, "待确认回单"),
    COMPLETE(9, "已完成"),
    UN_ACCEPT(21, "不接受"),
    DISCONTINUE(22, "已中止"),
    INVALID_STATE(99, "无效状态");

    private Integer code;

    PNOOuterStatusEnum(Integer code, String message) {
        this.code = code;
    }

    /**
     * 根据code获取message
     * */
    public static String getMessage(Integer code) {
        PNOOuterStatusEnum pnoOuterStatusEnum = Arrays.stream(PNOOuterStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return pnoOuterStatusEnum != null ? pnoOuterStatusEnum.getMessage() : PNOOuterStatusEnum.INVALID_STATE.getMessage();
    }

    /**
     * 获取供应商待新增生产通知单列表状态集
     * */
    public static List<Integer> getSupplierToBeAddListStatus() {
        return Stream.of(
                PNOOuterStatusEnum.UN_ACCEPT.getCode(),
                PNOOuterStatusEnum.TO_BE_SUBMIT.getCode()
        ).collect(Collectors.toList());
    }

    /**
     * 获取所有
     * */
    public static List<Map<String, Object>> getAll() {
        return Arrays.stream(PNOOuterStatusEnum.values()).map(a -> {
            Map<String, Object> map = new HashMap<>();
            map.put("code", a.getCode());
            map.put("message", a.getMessage());
            return map;
        }).collect(Collectors.toList());
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(),this.code);
    }

}
